//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    Seaid: '',
    DetailData: [],
    BusinessHeaderImage: '',
    BusinessAllName: '',
    AgentUserName: '',
    AgentHeaderImg: '',
    AgentTrueName: '',
    AgentUserName: '',
    HeHuoRenHeaderImg: '',
    HeHuoRenTrueName: '',
    HeHuoRenUserName: '',
    PartnerHeaderImg: '',
    PartnerTrueName: '',
    PartnerUserName: '',
    // 申请认领时间
    ClaimTime: '',
    // 判断申请
    IsClaim: '',
    pic: '',
    ClaimBeforeSixComeMa: '',
    ClaimBeforeSixComeOrderNum: '',
    ClaimAfterTwoComeMa: '',
    ClaimAfterTwoComeOrderNum: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var uid = wx.getStorageSync('uid');
    // var Seaid = wx.getStorageSync('Seaid');
    var userType = this.data.userType;
    userType = wx.getStorageSync('userType');

    this.setData({
      uid: uid,
      Seaid: options.Seaid,
      userType: userType,

    })
    // console.log(options);
    this.DevelopGetClaimBusinessInfo();
  },
  // 开发人员查看公海客户详情
  DevelopGetClaimBusinessInfo: function () {
    var that = this;
    var uid = this.data.uid;
    var Seaid = this.data.Seaid;
    var DetailData = this.data.DetailData;
    var BusinessHeaderImage = this.data.BusinessHeaderImage;
    var BusinessAllName = this.data.BusinessAllName;
    var AgentUserName = this.data.AgentUserName;
    var AgentHeaderImg = this.data.AgentHeaderImg;
    var AgentTrueName = this.data.AgentTrueName;
    var HeHuoRenHeaderImg = this.data.HeHuoRenHeaderImg;
    var HeHuoRenTrueName = this.data.HeHuoRenHeaderImg;
    var HeHuoRenUserName = this.data.HeHuoRenHeaderImg;
    var PartnerHeaderImg = this.data.PartnerHeaderImg;
    var PartnerTrueNam = this.data.PartnerTrueName;
    var PartnerUserName = this.data.PartnerUserName;
    var ClaimTime = this.data.ClaimTime;
    var IsClaim = this.data.IsClaim;
    var pic = this.data.pic;
    var ClaimBeforeSixComeMa = this.data.ClaimBeforeSixComeMa;
    var ClaimBeforeSixComeOrderNum = this.data.ClaimBeforeSixComeOrderNum;
    var ClaimAfterTwoComeMa = this.data.ClaimAfterTwoComeMa;
    var ClaimAfterTwoComeOrderNum = this.data.ClaimAfterTwoComeOrderNum;
    // console.log(IsClaim);
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=DevelopGetClaimBusinessInfo&UID=" + uid + "&SeaId=" + Seaid),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        console.log(json);
        if (IsClaim == 0) {
          pic = true;
          ClaimTime = false;
        } if (IsClaim == 1) {
          ClaimTime = true
          pic = false;
        }
        that.setData({
          DetailData: DetailData,
          BusinessHeaderImage: json.BusinessHeaderImage,
          BusinessAllName: json.BusinessAllName,
          AgentUserName: json.AgentUserName,
          AgentHeaderImg: json.AgentHeaderImg,
          AgentTrueName: json.AgentTrueName,
          HeHuoRenHeaderImg: json.HeHuoRenHeaderImg,
          HeHuoRenTrueName: json.HeHuoRenTrueName,
          HeHuoRenUserName: json.HeHuoRenUserName,
          PartnerHeaderImg: json.PartnerHeaderImg,
          PartnerTrueName: json.PartnerTrueName,
          PartnerUserName: json.PartnerUserName,
          ClaimTime: json.ClaimTime,
          IsClaim: json.IsClaim,
          ClaimBeforeSixComeMa: json.ClaimBeforeSixComeMa,
          ClaimBeforeSixComeOrderNum: json.ClaimBeforeSixComeOrderNum,
          ClaimAfterTwoComeMa: json.ClaimAfterTwoComeMa,
          ClaimAfterTwoComeOrderNum: json.ClaimAfterTwoComeOrderNum,
        })

      }
    })
  },

  // 申请服务
  clickApplyfor: function () {
    var that = this;
    var uid = this.data.uid;
    var Seaid = this.data.Seaid;
    var ClaimTime = this.data.ClaimTime;
    wx.showModal({
      title: '提示',
      content: '是否确认对该商户进行再次服务？（名额有限，请谨慎操作）',
      success(res) {
        if (res.confirm) {
          console.log("method=DeveloperClaimBusiness&UID=" + uid + "&SeaId=" + Seaid);
          wx.request({
            url: baseJs.api + baseJs.encryUrl("method=DeveloperClaimBusiness&UID=" + uid + "&SeaId=" + Seaid),
            success: function (res) {
              var json = JSON.parse(baseJs.decryUrl(res.data));
              console.log(json);
              if (json.ResultFlag == 1) {
                // hidden = true;
                wx.showToast({
                  title: '申领成功，请去申领服务中查看！',
                  icon: 'none',
                  duration: 2000
                });
                // that.onload();
                setTimeout(function () {
                  wx.navigateBack({
                    delta: 3
                  })
                }, 1000)
              }
              if (json.ResultFlag == 0) {
                wx.showToast({
                  title: json.ResultMsg,
                  icon: 'none',
                  duration: 2000
                });
              }
              that.setData({
                ClaimTime: json.ResultData.ClaimTime,
              })
            }
          })
        } else if (res.cancel) {

        }
      }
    })


  },
  // 开发人员已认领客户数据
  DeveloperClaimBusinessData: function () {
    var that = this;
    var uid = this.data.uid;
    var FinishClaimNum = this.data.FinishClaimNum;
    var ServiceClaimNum = this.data.ServiceClaimNum;
    var SupplyClaimNum = this.data.SupplyClaimNum;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=DeveloperClaimBusinessData&UID=" + uid),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        console.log(json);
        that.setData({
          FinishClaimNum: json.ResultData.FinishClaimNum,
          ServiceClaimNum: json.ResultData.ServiceClaimNum,
          SupplyClaimNum: json.ResultData.SupplyClaimNum,
        })

      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})